package com.tudouji.project.bill.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.bill.domain.AutoTransfer;
import com.tudouji.project.bill.service.IAutoTransferService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 自动调拨Controller
 * 
 * @author tudouji
 * @date 2023-08-30
 */
@RestController
@RequestMapping("/bill/transfer")
public class AutoTransferController extends BaseController
{
    @Autowired
    private IAutoTransferService autoTransferService;

    /**
     * 查询自动调拨列表
     */
    @PreAuthorize("@ss.hasPermi('bill:transfer:list')")
    @GetMapping("/list")
    public TableDataInfo list(AutoTransfer autoTransfer)
    {
        startPage();
        List<AutoTransfer> list = autoTransferService.selectAutoTransferList(autoTransfer);
        return getDataTable(list);
    }

    /**
     * 导出自动调拨列表
     */
    @PreAuthorize("@ss.hasPermi('bill:transfer:export')")
    @Log(title = "自动调拨", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AutoTransfer autoTransfer)
    {
        List<AutoTransfer> list = autoTransferService.selectAutoTransferList(autoTransfer);
        ExcelUtil<AutoTransfer> util = new ExcelUtil<AutoTransfer>(AutoTransfer.class);
        return util.exportExcel(list, "transfer");
    }

    /**
     * 获取自动调拨详细信息
     */
    @PreAuthorize("@ss.hasPermi('bill:transfer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(autoTransferService.selectAutoTransferById(id));
    }

    /**
     * 新增自动调拨
     */
    @PreAuthorize("@ss.hasPermi('bill:transfer:add')")
    @Log(title = "自动调拨", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AutoTransfer autoTransfer)
    {
        return toAjax(autoTransferService.insertAutoTransfer(autoTransfer));
    }

    /**
     * 修改自动调拨
     */
    @PreAuthorize("@ss.hasPermi('bill:transfer:edit')")
    @Log(title = "自动调拨", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AutoTransfer autoTransfer)
    {
        return toAjax(autoTransferService.updateAutoTransfer(autoTransfer));
    }

    /**
     * 删除自动调拨
     */
    @PreAuthorize("@ss.hasPermi('bill:transfer:remove')")
    @Log(title = "自动调拨", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(autoTransferService.deleteAutoTransferByIds(ids));
    }
}
